Page({
  data: {
    name: '',
    age: '',
    genderList: ['男', '女'],
    selectedGender: '男',
    remark: ''
  },
  handleNameInput(e) {
    this.setData({
      name: e.detail.value
    });
  },
  handleAgeInput(e) {
    this.setData({
      age: e.detail.value
    });
  },
  handleGenderChange(e) {
    this.setData({
      selectedGender: this.data.genderList[e.detail.value]
    });
  },
  handleRemarkInput(e) {
    this.setData({
      remark: e.detail.value
    });
  },
  saveInfo() {
    const { name, age, selectedGender, remark } = this.data;
    if (!name || !age) {
      wx.showToast({
        title: '姓名和年龄不能为空',
        icon: 'none'
      });
      return;
    }
    const newInfo = {
      name,
      age,
      gender: selectedGender,
      remark
    };
    let userInfoList = wx.getStorageSync('userInfoList') || [];
    userInfoList.push(newInfo);
    wx.setStorageSync('userInfoList', userInfoList);
    wx.showToast({
      title: '信息保存成功',
      icon: 'success'
    });
    wx.navigateBack();
  }
});